let http = require('http');
let fs = require('fs');
let app = http.createServer(function (req,res) {
    fs.readFile('app.html',function(err,data){
        res.writeHead(200,{'Content-type':'text/html;charset=utf-8'});
        res.end(data);
    });
});



//引入io
let io = require('socket.io')(app);
io.on('connection',function(socket){
    console.log('服务器建立连接了');
    //接收客户端传过来的数据
    socket.on('addcart',function(data){
        console.log(data);
    });
    //向客户端广播数据
    io.emit('to-client',{
        server:'data from server'
    });

});

app.listen(3000);